package com.android.dialer.service;

import android.content.Intent;
import android.os.Build;
import androidx.annotation.RequiresApi;
import android.telecom.Call;
import android.telecom.InCallService;

import com.android.dialer.TelecomActivity;
import com.android.dialer.util.CallManager;
import com.android.incallui.Log;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

/**
 * @author HYL
 * @date 2020/11/3
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public class InCallServiceImpl extends InCallService {

    @Override
    public void onCallAdded(final Call call) {
        super.onCallAdded(call);
        Log.e("AD-HYL", "call added");
        CallManager.getInstance().setCall(call);

        startActivity(new Intent(this, TelecomActivity.class).addFlags(FLAG_ACTIVITY_NEW_TASK));
    }

    @Override
    public void onCallRemoved(Call call) {
        super.onCallRemoved(call);
        CallManager.getInstance().setCall(null);
        Log.e("AD-HYL", "call removed");
    }
}
